// Copyright 2024 FastLabs Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use logforth::{
    append,
    filter::{env_filter::EnvFilterBuilder, reload::ReloadFilter, EnvFilter},
};

fn main() {
    let (filter, reload_handle) = ReloadFilter::new(EnvFilter::new(
        EnvFilterBuilder::new().filter_level(log::LevelFilter::Off),
    ));

    logforth::builder()
        .dispatch(|d| d.filter(filter).append(append::Stdout::default()))
        .apply();

    log::error!("Hello error!"); // not show
    log::warn!("Hello warn!"); // not show
    log::info!("Hello info!"); // not show
    log::debug!("Hello debug!"); // not show
    log::trace!("Hello trace!"); // not show

    reload_handle
        .modify(|filter| {
            *filter = EnvFilter::new(EnvFilterBuilder::new().filter_level(log::LevelFilter::Trace))
        })
        .unwrap();

    log::error!("Hello error! -- reload"); // show
    log::warn!("Hello warn! -- reload"); // show
    log::info!("Hello info! -- reload"); // show
    log::debug!("Hello debug! -- reload"); // show
    log::trace!("Hello trace! -- reload"); // show
}
